// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1

package svc

import (
	"audio-server/internal/config"
	"audio-server/internal/db"
	_ "log"

	"github.com/volcengine/ve-tos-golang-sdk/v2/tos"
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

type ServiceContext struct {
	Config    config.Config
	Conn      sqlx.SqlConn
	Redis     *redis.Redis
	TOSClient *tos.ClientV2
}

func NewServiceContext(c config.Config) *ServiceContext {
	sqlConn := db.NewMysql(c.MysqlConfig)
	credential := tos.NewStaticCredentials(c.TosConfig.AccessKey, c.TosConfig.SecretKey)
	client, err := tos.NewClientV2(c.TosConfig.Endpoint, tos.WithCredentials(credential), tos.WithRegion(c.TosConfig.Region))
	if err != nil {
		panic(err) // 或者使用更合适的错误处理方式
	}
	return &ServiceContext{
		Config:    c,
		Conn:      sqlConn,
		Redis:     redis.MustNewRedis(c.RedisConf),
		TOSClient: client,
	}
}
